<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程包列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <li>
                            <label>名称：</label>
                            <input type="text" name="name"/>
                            <input type="hidden" name="parentId" value="0"/>
                        </li>
                        <li>
                            <label >类型：</label>
                            <select name="typeName" class="form-control m-b" th:with="type=${@dict.getType('course_package_type')}">
                                <option value="">---全部---</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <input type="file" name="upload" id="upload" style="display: none;" />
        <input type="hidden" name="id" id="id" style="display: none;" th:value="${id}" />
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:package:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:package:remove')}]];
    var prefix = ctx + "system/package";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            importUrl: prefix + "/importData",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "课程包",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '课程包id，课程包是所有单节课程的集合',
                    visible: false
                },

                {
                    field: 'name',
                    title: '课程包名称'
                },
                {
                    field: 'typeName',
                    title: '类型',
                    formatter: function(value, item, index) {
                        return typeName(item.typeName);
                    }
                },
                {
                    field: 'tags',
                    title: '标签'
                },
                {
                    field: 'ageLow',
                    title: '月龄 低限'
                },
                {
                    field: 'ageHigh',
                    title: '月龄 高限'
                },
                {
                    field: 'orderNum',
                    title: '排序'
                },
                {
                    field: 'created',
                    title: '创建时间'
                },
                {
                    field: 'createdName',
                    title: '创建人'
                },
                {
                    field: 'cover',
                    title: '封面',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return '<img  src="'+row.cover+'" height="150" width="150">';
                    }
                }]
        };
        $.table.init(options);
    });

    function onFile(id) {
        $('#id').val(id);
        $('#upload').click();
    }

    function addParent(id) {
        var url = prefix + '/addParent?id=' + id;
        $.modal.open("添加周", url);
    }


    function parentPackages(id) {
        var url = prefix + '/parentPackages?id=' + id;
        $.modal.openTab("课程包周", url);
    }

    $('#upload').on('change', function(){
        var farmdate = new FormData();
        farmdate.append("file",$('#upload')[0].files[0]);
        farmdate.append("id",$('#id').val());
        $.ajax({
            type:"post",
            url:prefix+"/importData",
            data:farmdate,
            contentType:false,
            processData:false,
            success:function (date) {
                $.modal.alertSuccess("添加成功")
                $.table.refresh();
            }
        })
    });


    function typeName(typeName) {
        if (typeName==null || typeName ==undefined || typeName==''){
            return '';
        }
        var type  = typeName.split(',');
        var content = "";
        for (let i = 0; i < type.length; i++) {
            if (type[i] == "0") {
                content += '<span class="label label-success">机构端</span>';
            } else if (type[i] == '1') {
                content += '<span class="label label-primary">家庭端</span>';
            } else if (type[i] == '2') {
                content += '<span class="label label-warning">小群体课程</span>';
            }
        }
        return content;
    }
    var time = 0;
    /* 拷贝周-提交 */
    function submitHandler() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("请选择一条记录");
            return;
        }
        var  packagesId = $("#id").val();
        var data = { "packagesId": packagesId ,"id" : rows.join() };
        if (time==0) {
            time = 1;
            $.operate.save(prefix + "/copyWeekPackages", data);
        }
    }
</script>

</body>
</html>